
var isValidSudoku = function(board) {
    // rows[i][index] 表示index+1出现的次数
    let rows = new Array(9).fill(0).map(()=>new Array(9).fill(0))
    let colums = new Array(9).fill(0).map(()=>new Array(9).fill(0))
    // subboxes[i][j][index] 表示index+1出现的次数
    let subbboxes = new Array(3).fill(0).map(()=>new Array(3).fill(0).map(()=>new Array(9).fill(0)))
    for(var i = 0;i<board.length;i++) {
      for(var j = 0;j<board[0].length;j++) {
        const b = board[i][j]
        if(b!=='.'){
          let index = parseInt(b)-1
          rows[i][index]++
          colums[j][index]++
          subbboxes[Math.floor(i/3)][Math.floor(j/3)][index]++
          if(rows[i][index]>1||colums[j][index]>1||subbboxes[Math.floor(i/3)][Math.floor(j/3)][index]>1) return false
        }
      }
    }
    return true
};
var board = 
[["5","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]
console.log(isValidSudoku(board));